<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="example">
        <label for="username">请输入用户名</label>
       <input type="text" id="username" v-model.lazy="message"></input>
        {{tip}}
    </div>

    <script src="../../js/vue.js"></script>
    <script>
        var vm = new Vue({
            el: '#example',
            data: {
                message: 'Hello',
                tip: ""
            },
            watch: {
                message:function(newValue, oldValue){
                    this.tip = "验证用户名。。。"
                    console.log('~~', newValue, oldValue)
                    // 仿造假设异步
                    setTimeout(() => {
                        if(this.message == "main"){
                            this.tip = "用户名已被注册，请重新输入用户名！"
                        }else{
                            this.tip = "用户名未被注册，该用户名可以使用-_--!"
                        }
                    }, 2000);
                }
            }
        })
    </script>
</body>

</html>